package cn.powerone.scm.controller;

import java.util.List;

import cn.powerone.scm.service.IScmSequenceParmService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmProjects;
import cn.powerone.scm.service.IScmProjectsService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 项目管理Controller
 * 
 * @author PowerOne
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/scm/projects")
public class ScmProjectsController extends BaseController
{
    @Autowired
    private IScmProjectsService scmProjectsService;

    @Autowired
    private IScmSequenceParmService scmSequenceParmService;

    /**
     * 查询项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('scm:projects:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmProjects scmProjects)
    {
        startPage();
        List<ScmProjects> list = scmProjectsService.selectScmProjectsList(scmProjects);
        return getDataTable(list);
    }

    /**
     * 导出项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('scm:projects:export')")
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmProjects scmProjects)
    {
        List<ScmProjects> list = scmProjectsService.selectScmProjectsList(scmProjects);
        ExcelUtil<ScmProjects> util = new ExcelUtil<ScmProjects>(ScmProjects.class);
        util.exportExcel(response, list, "项目管理数据");
    }

    /**
     * 获取项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:projects:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(scmProjectsService.selectScmProjectsByProjectId(projectId));
    }

    /**
     * 新增项目管理
     */
    @PreAuthorize("@ss.hasPermi('scm:projects:add')")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmProjects scmProjects)
    {
        scmProjects.setProjectCode(scmSequenceParmService.generateScmSequence("project_code"));
        return toAjax(scmProjectsService.insertScmProjects(scmProjects));
    }

    /**
     * 修改项目管理
     */
    @PreAuthorize("@ss.hasPermi('scm:projects:edit')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmProjects scmProjects)
    {
        return toAjax(scmProjectsService.updateScmProjects(scmProjects));
    }

    /**
     * 删除项目管理
     */
    @PreAuthorize("@ss.hasPermi('scm:projects:remove')")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(scmProjectsService.deleteScmProjectsByProjectIds(projectIds));
    }
}
